package com.cykj.service.impl;

import com.cykj.dto.ResponseDTO;
import com.cykj.entity.CourseDO;
import com.cykj.mapper.CourseMapper;
import com.cykj.service.ICourseService;
import com.cykj.vo.CourseVO;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import java.util.Iterator;
import java.util.List;

/**
 * @Program: Mooc-Admin
 * @Package: com.cykj.service.impl
 * @Author: 张俊杰
 * @Create: 2025-07-09 11:33
 * @Description: TODO
 * @Vision: 1.0
 **/
@Service
public class CourseServiceImpl implements ICourseService {
    @Autowired
    private CourseMapper courseMapper;

    @Override
    public ResponseDTO getListCourse(CourseVO courseVO) {

        PageHelper.startPage(courseVO.getPageNum(), courseVO.getPageSize());

        List<CourseDO> list = courseMapper.getListCourse(courseVO);

        PageInfo<CourseDO> courseDOPageInfo = new PageInfo<>(list);
        return ResponseDTO.success(courseDOPageInfo);
    }

    @Override
    public ResponseDTO deleteCourse(Integer courseId) {

        Integer i = courseMapper.deleteCourse(courseId);
        if (i > 0) {
            return ResponseDTO.effectRow(i);
        }
        return ResponseDTO.error("删除失败");
    }

    @Override
    public ResponseDTO addCourse(CourseDO courseDO) {
        Integer i = courseMapper.addCourse(courseDO);
        if (i > 0) {
            return ResponseDTO.effectRow(i);
        }
        return ResponseDTO.error("添加失败");
    }

    @Override
    public ResponseDTO updateCourse(CourseDO courseDO) {

        Integer i = courseMapper.updateCourse(courseDO);
        if (i > 0) {
            return ResponseDTO.effectRow(i);
        }
        return ResponseDTO.error("修改失败");
    }
}
